#include <etcd/Client.hpp>
#include <etcd/KeepAlive.hpp>
#include <etcd/Response.hpp>
#include <iostream>
#include <string>
#include <thread>

int main()
{
    std::string etcd_host = "http://127.0.0.1:2379";
    etcd::Client client(etcd_host);
    // 设置租约时长并返回
    std::shared_ptr<etcd::KeepAlive> keep_alive = client.leasekeepalive(3).get();     
    // 获取租约ID
    int64_t lease_id = keep_alive->Lease();
    // 新增数据
    etcd::Response resp = client.put("/service/user", "127.0.0.1:8000", lease_id).get();
    if(!resp.is_ok()) {
        std::cout << "新增数据失败: " << resp.error_message() << '\n';
        return 1;
    }

    etcd::Response resp2 = client.put("/service/friend", "127.0.0.1:9000").get();
    if(!resp2.is_ok()) {
        std::cout << "新增数据失败: " << resp2.error_message() << '\n';
        return 1;
    }

    this_thread::sleep_for(std::chrono::seconds(10));
    return 0;
}
